/**
 * 日期工具类
 */
class DateTime {
  // 构造方法  
  constructor() {
    // 列举Week    
    this.weekday = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
    // 获取当前时间    
    this.Date = new Date();
    // 获取当前年    
    this.year = this.Date.getFullYear();
    // 获取当前月   
    this.month = this.Date.getMonth() + 1; //
    // 获取当前日    
    this.date = this.Date.getDate();
    // 获取当前星期几    
    this.day = this.Date.getDay();
    // 获取小时    
    this.hour = this.Date.getHours();
    // 获取分钟    
    this.minute = this.Date.getMinutes();
    // 获取秒    
    this.second = this.Date.getSeconds();
    // 自动补零    
    this.month = (this.month < 10) ? '0' + this.month : this.month = this.month;
    this.date = (this.date < 10) ? '0' + this.date : this.date = this.date;
    this.minute = (this.minute < 10) ? '0' + this.minute : this.minute = this.minute;
    this.second = (this.second < 10) ? '0' + this.second : this.second = this.second;
  };
  /**   * 获取时间错   * @returns {string}*/
  getTimeStamp() {
    return Date.parse(new Date()) + ' ';
  };
  /**   * 获取当前日期   * @returns {string}*/
  getDate(isChinise) {
    if(isChinise){
      return this.year + '年' + this.month + '月' + this.date + '日' + ' ';
    }else{
      return this.year + '-' + this.month + '-' + this.date + ' ' + ' ';
    }
  };
  /**   * 获取当前时间   * @returns {string}*/
  getTime() {
    return this.hour + ':' + this.minute + ':' + this.second;
  };
  /**   * 获取当前星期几   * @returns {string}*/
  getWeek() {
    return this.weekday[this.day]
  };
  // 获取当年
  getYear() {
    return this.year;
  };
  // 获取本月
  getMonth() {
    return this.month;
  };
  //格式化日期：yyyy-MM-dd 
  formatDate(date) {
    var myyear = date.getFullYear();
    var mymonth = date.getMonth() + 1;
    var myweekday = date.getDate();
    if (mymonth < 10) {
      mymonth = "0" + mymonth;
    }
    if (myweekday < 10) {
      myweekday = "0" + myweekday;
    }
    return (myyear + "-" + mymonth + "-" + myweekday);
  };

  //获得某月的天数 
  getMonthDays(myMonth) {
    myMonth = parseInt(myMonth);
    var monthStartDate = new Date(this.year, myMonth, 1);
    var monthEndDate = new Date(this.year, myMonth + 1, 1);
    var days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24);
    return days;
  };

  //获得本季度的开始月份 
  getQuarterStartMonth() {
    var quarterStartMonth = 0;
    if (this.month-1 < 3) {
      quarterStartMonth = 0;
    }
    if (2 < this.month-1 && this.month-1 < 6) {
      quarterStartMonth = 3;
    }
    if (5 < this.month-1 && this.month-1 < 9) {
      quarterStartMonth = 6;
    }
    if (this.month-1 > 8) {
      quarterStartMonth = 9;
    }
    return quarterStartMonth;
  };

  //获得本周的开始日期 
  getWeekStartDate() {
    var weekStartDate = new Date(this.year, this.month-1, this.date - this.day + 1);
    return this.formatDate(weekStartDate);
  };

  //获得本周的结束日期 
  getWeekEndDate() {
    var weekEndDate = new Date(this.year, this.month-1, this.date + (7 - this.day));
    return this.formatDate(weekEndDate);
  };

  //获得本月的开始日期 
  getMonthStartDate() {
    var monthStartDate = new Date(this.year, this.month-1, 1);
    return this.formatDate(monthStartDate);
  };

  //获得本月的结束日期 
  getMonthEndDate() {
    var monthEndDate = new Date(this.year, this.month-1, this.getMonthDays(this.month-1));
    return this.formatDate(monthEndDate);
  };
  //获取当前月 天数集合
  getCurMonthDayArray() {
    var dayArray = [];
    var totalDay = this.getMonthDays(this.month-1);
    console.log(totalDay);
    for (let i = 1; i <= totalDay; i++) {
      dayArray.push(i < 10 ? "0" + i : i + "");
    }
    return dayArray;
  };

  //获得本季度的开始日期 
  getQuarterStartDate() {

    var quarterStartDate = new Date(this.year, this.getQuarterStartMonth(), 1);
    return this.formatDate(quarterStartDate);
  };

  //或的本季度的结束日期 
  getQuarterEndDate() {
    var quarterEndMonth = this.getQuarterStartMonth() + 2;
    var quarterStartDate = new Date(this.year, quarterEndMonth, this.getMonthDays(quarterEndMonth));
    return this.formatDate(quarterStartDate);
  };
  //js获取连个时间间隔天数date1，date2为date类型
  dateReduce (date1, date2) {
    var sdate = new Date(date1);
    var now = new Date(date2);
    var days = now.getTime() - sdate.getTime();
    var day = parseInt(days / (1000 * 60 * 60 * 24));
    return day;
  }
};
export {
  DateTime
}
